package org.jground.rx.ui.zk;

import org.jground.rx.IRXObject;
import org.jground.rx.web.UIProperties;
import org.jground.util.DateUtils;
import org.jground.zk.zulX.DivX;
import org.zkoss.zul.Label;

public class UIDataObjectInfoBar extends DivX {

    private Label label = new Label();

    private String created;
    private String modified;
    private String status;
    private String by;
    private String nr;
    private String checkedOutBy;

    public UIDataObjectInfoBar() {
        // init label
        initLabels();
        //        
        label.setParent(this);
        label.setSclass(UIStyles.BAR);
        setSclass(UIStyles.BAR);
    }

    private void initLabels() {
        created = UIProperties.getInstance().getUILabel("created");
        modified = UIProperties.getInstance().getUILabel("modified");
        status = UIProperties.getInstance().getUILabel("status");
        by = UIProperties.getInstance().getUILabel("by");
        nr = UIProperties.getInstance().getUILabel("nr");
        checkedOutBy = UIProperties.getInstance().getUILabel("checkedOutBy", "checked out by");
    }

    public void setData(IRXObject mod) {

        String userName = mod.getCheckedOutUser();
        label.setValue(nr + ":" + mod.getOid() + " " + created + ":"
                + DateUtils.formatToDateTime(mod.getCreationTime()) + " " + by + ":" + mod.getCreator() + "; "
                + modified + ":" + DateUtils.formatToDateTime(mod.getLastModifiedTime()) + " " + by + ":"
                + mod.getLastUserName() + " " + status + ":" + mod.getDataState()
                + (userName != null ? " " + checkedOutBy + ":" + userName : ""));
    }
}
